<?php



require_once 'Snoopy.class.php';
//require_once "/mysql_connect.php"; //connect
//require_once 'water.php';//水印

function str_substr($start, $end, $str) // 字符串截取函数     
{     
    $temp = explode($start, $str, 2);     
    $content = explode($end, $temp[1], 2);     
    return $content[0];     
} 


set_time_limit(0);

$url = "http://price.pcauto.com.cn/cars/";      
$snoopy = new Snoopy;   
$snoopy->fetch($url); //获取所有内容    

$snoopy->cookies["PHPSESSID"] = 'fc106b1918bd522cc863f36890e6fff7'; //伪装sessionid   
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; //伪装浏览器   
$snoopy->referer = "http://www.google.com"; //伪装来源页地址 http_referer   
$snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息   
$snoopy->rawheaders["X_FORWARDED_FOR"] = "127.0.0.1"; //伪装ip   
$snoopy->submit($action,$formvars);   
$snoopy->expandlinks = true; //是否补全链接

$results= $snoopy->results;//输出全文



//输出DT品牌
$results=str_substr('<div class="letters">', "<script>", $results);



preg_match_all("/<tr>|(.+?)<\/tr>/",$results,$page);

print_r($page);
exit();

foreach ($page[1] as $out_dt) {
	//dt_name 一汽奥迪 进口奥迪 进口阿斯顿马丁
	$dt_name=str_substr("\">", "</a>", $out_dt);
	//$dt_name=str_ireplace("</a>","",$dt_name);
	$out_dt=str_substr("href=\"", "\"", $out_dt);
	//echo $dt_name;
	

	
	//DT_NAME URL 输出车型URL
	//$out_dt="http://price.pcauto.com.cn/brand.jsp?bid=1";  
    $snoopy->fetch($out_dt); //获取所有内容 
	$dt_results= $snoopy->results;//全文
	$dt_results=str_substr('<div class="sellerInfo end">', "</ul>", $dt_results);
	preg_match_all("/<i(.+?)<\/a>/",$dt_results,$out_page);
	foreach ($out_page[1] as $main_page) {
		$main_txt=str_substr('title="', '"', $main_page);
		$main_txt=substr($main_txt,0,-4);
		$main_page=str_substr('href="', '"', $main_page);
		$main_page=str_ireplace("_price","",$main_page);
		
	//echo $main_txt."|<br>";

	$father_id = DB::fetch_first("SELECT * FROM ".DB::table('car_brand')."  WHERE  model = '$main_txt' ");
	$father_id = $father_id['id'];
	
	if (!empty($main_txt)){
	
	//echo $main_txt."_".$main_page;
	//车型内容输出
	//$main_page="http://price.pcauto.com.cn/serial.jsp?sid=3524";  
    $snoopy->fetch($main_page); //获取所有内容    
    $main_results= $snoopy->results;//全文
	//echo $main_results;
    //$results=iconv("gb2312","UTF-8",$results);//GBK OR U8
	$main_results=str_substr('<div class="tbA" id="typeList">', "</table>", $main_results);
	

	preg_match_all("/<span>(.+?)<\/span>/",$main_results,$out_main);
	foreach ($out_main[1] as $allmain) {
	$all_main=str_substr('title="', '/a>', $allmain);
	$all_main=str_substr('">', '<', $all_main);
	
	$all_url=str_substr('href=', '/model/', $allmain);
	$all_url=str_substr('"', '/"', $all_url);
	$all_url=$all_url."/model/";
	
	//echo $all_main."-".$all_url."<br>";
	//取内容
	//$all_url="http://price.pcauto.com.cn/m15827/model/";
	$snoopy->fetch($all_url); //获取所有内容    
    $all_results= $snoopy->results;//全文
	//echo $all_results;
    //$all_results=iconv("gb2312","UTF-8",$all_results);//GBK OR U8
	

	$all_results=str_substr('<div class="modA mgb10 modCS">', '<div class="right230">', $all_results);
	//preg_match_all("/<table(.+?)<\/table>/",$all_results,$out_all);
	$all_results = ereg_replace("<a [^>]*>|<\/a>","",$all_results);//去除超链接 小a
	$all_results = ereg_replace("<p class=\"side\">[^>]*>|<\/p>","",$all_results);
	$all_results = ereg_replace("<p class=\"height\">[^>]*>|<\/p>","",$all_results);
	$all_results = ereg_replace("<p class=\"front\">[^>]*>|<\/p>","",$all_results);
	$all_results = ereg_replace("<p class=\"behind\">[^>]*>|<\/p>","",$all_results);
	$all_results = ereg_replace("<p class=\"txt\">[^>]*>|<\/p>","",$all_results);
	//$all_results = ereg_replace("<div class=\"pic_CS\"> [^>]*>|<\/div>","",$all_results);
	
	
	$all_div = '<div class="modA mgb10 modCS">';
	$all_css = '<link rel="stylesheet" href="css/car_brand.css" type="text/css" media="all" />';
	$all_results = $all_div.$all_results.$all_css;
	//echo $all_results;

	/*
	if (!(empty($all_results))){
		
		$id = DB::fetch_first("SELECT * FROM ".DB::table('car_brand')."  WHERE  model = '$all_main' AND father_id = '$father_id' ");
		$id = $id['id'];
		//echo $father_id."-".$allmain."<br>";
		//echo $id."<br>";

			$query = "
			UPDATE 
			".DB::table('car_brand')." 
			SET config = '$all_results' WHERE id = '$id'
			";
			$query = DB::query($query);

	}*/
	}

	}


	}//正文

}

?>